package com.wmyg.antifake.interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

public class LoginInterceptor implements HandlerInterceptor{

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println(request.getRequestURI());
        Object user = request.getSession().getAttribute("loginUser");
        request.setAttribute("msg","没有权限");
       // return true;//不设置登陆拦截
        if (user == null){
            response.getWriter().print("<script>window.top.location.href='/antifake/'</script>");
            return false;
        }else {
            return true;
        }
    }
}
